package br.com.hs.biosys.business.implementation;

import br.com.hs.biosys.application.ApplicationConfig;
import br.com.hs.biosys.util.security.Criptografy;
import br.com.hs.biosys.business.UserBC;
import br.com.hs.biosys.model.domain.User;
import br.com.hs.biosys.model.persistence.implementation.JPAUserDAO;
import br.gov.frameworkdemoiselle.template.DelegateCrud;
import javax.inject.Inject;

/**
 * UserBCImpl.class
 *
 * @author Ranlive Hrysyk
 * @since 19/07/2012
 */
public class UserBCImpl extends DelegateCrud<User, Long, JPAUserDAO> implements UserBC {

    private static final long serialVersionUID = 1L;
    /**
     * Configurações da aplicação.
     */
    @Inject
    private ApplicationConfig config;

    /**
     * Constructor default.
     */
    public UserBCImpl() {
    }

    @Override
    public boolean validateUserPassword(User user, String password) {
        Criptografy criptografy = new Criptografy(config.getDigestAlgorithm(), config.getEncoding());
        return user.getPassword().equals(criptografy.encrypt(password));
    }
}
